<?php
namespace app\index\domain;

class Address extends BaseList
{
    //后续连贯标签
    static protected $tags = [
        'first'=>[],
        'list'=>[],
    ];

    public function __construct($id)
    {
        $this->_id = $id;
    }

    /**
     * 获取列表中某个内容的数据对象
     */
    protected function createObj($objParam)
    {
        //return new Term($objParam['id'], 'id');
        return Classes::get('Term', $objParam);
    }

    public function valueGet($key)
    {
        if(isset($this->getList()[$key])){
            $index = $this->getList()[$key];
            return $this->createObj($index);
        }
        return null;
    }

    public function getFirst()
    {
        if(!empty($this['list'])){
            $list = $this->getList();
            $first = reset($list);
            return $this->createObj($first);
        }
        return null;
    }

    /**
     * 根据参数组获取列表
     */
    protected function getList()
    {
        $cacheKey = md5('contentList'.serialize($this->_id));
        if(isset($this->_cache[$cacheKey]))
            return $this->_cache[$cacheKey];
        if($address = D('index/Term')->getAddress($this->_id)){
            return $this->_cache[$cacheKey] = $address;
        }
        return [];
    }
}

